<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //   document.addEventListener("myevent1", function () {
      //     console.log("点击了");
      //   });

      // 创建事件类
      let eventObj = new EventTarget();

      // 绑定自定义事件
      eventObj.addEventListener("myevent1", function () {
        console.log(111);
      });
      eventObj.addEventListener("myevent1", function () {
        console.log(222);
      });
      let fn = function () {
        console.log(333);
      };

      eventObj.addEventListener("myevent1", fn);
      // 移除自定义事件 ；
      eventObj.removeEventListener("myevent1", fn);
      // 触发事件
      setTimeout(() => {
        eventObj.dispatchEvent(new CustomEvent("myevent1"));
      }, 2000);
    </script>
  </body>
</html>
